package com.justnow.offer;

import java.util.Scanner;

/**
 * @author justnow
 * Created on 2020-09-07
 * Description
 */
public class Beike01 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        scanner.nextLine();
        String[] arr = new String[T];
        for (int i = 0; i < T; i++) {
            String s = scanner.nextLine();
            System.out.println(getResult(s));
        }
    }

    public static String getResult(String s) {
        String[] str = s.split(" ");
        String result = "";
        int leftCount = charge(str[0], str[2]) + charge(str[0], str[3]);
        int rightCount = charge(str[1], str[2]) + charge(str[1], str[3]);
        if (leftCount < rightCount)
            result = "right";
        else if (leftCount == rightCount)
            result = "same";
        else
            result = "left";
        return result;
    }

    public static int charge(String s1, String s2) {
        int result = 0;
        if (s1.equals("S") && s2.equals("S"))
            return -1;
        if (s1.equals("S") && s2.equals("J"))
            return 1;
        if (s1.equals("S") && s2.equals("B"))
            return -1;
        if (s1.equals("J") && s2.equals("J"))
            return -1;
        if (s1.equals("J") && s2.equals("S"))
            return -1;
        if (s1.equals("J") && s2.equals("B"))
            return 1;
        if (s1.equals("B") && s2.equals("B"))
            return -1;
        if (s1.equals("B") && s2.equals("J"))
            return -1;
        if (s1.equals("B") && s2.equals("S"))
            return 1;
        return result;
    }
    
}
